//
//  XFStatues.m
//  SinaBlog_OC
//
//  Created by macs on 15/11/16.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

#import "XFStatues.h"

@implementation XFStatues

- (NSArray *)danLoadPicUrl {

  if (self.retweetes.pictureUrl.count != 0) {

    return self.retweetes.pictureUrl;
  }
  return self.pictureUrl;
}

- (NSArray *)pictureUrl {

  if (self.pic_urls != nil) {
    NSMutableArray *array =
        [NSMutableArray arrayWithCapacity:self.pic_urls.count];

    for (NSDictionary *urlDict in self.pic_urls) {
      NSURL *url = [NSURL URLWithString:urlDict[@"thumbnail_pic"]];
      [array addObject:url];
    }
    return array;
  }
  return nil;
}

+ (instancetype)statuesWithDict:(NSDictionary *)dict {

  XFStatues *statues = [[XFStatues alloc] init];

  [statues setValuesForKeysWithDictionary:dict];
  return statues;
}

- (void)setValue:(id)value forKey:(NSString *)key {

  if ([key isEqual:@"id"]) {
    [super setValue:value forKey:@"ids"];
    return;
  }

  if ([key isEqualToString:@"user"]) {
    self.user = [XFUser userWithDict:value];
    return;
  }

  if ([key isEqualToString:@"retweeted_status"]) {
    self.retweetes = [XFStatues statuesWithDict:value];
    return;
  }

  [super setValue:value forKey:key];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
}

@end
